import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';


const scene = new THREE.Scene();

// 创建mesh
const geometry = new THREE.BoxGeometry(100, 100, 100);
// 创建材质,MeshLambertMaterial是一个光照材质，需要光源才能显示颜色
const material = new THREE.MeshLambertMaterial({
	color: new THREE.Color("orange"),
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 0, 0);
scene.add(mesh);

// 创建光源
const pointLight = new THREE.PointLight(0xffffff, 10000);
pointLight.position.set(80, 80, 80); // 设置光源位置
scene.add(pointLight);

// 创建相机
const camera = new THREE.PerspectiveCamera(
	60,
	window.innerWidth / window.innerHeight,
	0.1,
	1000 // 相机的范围
);
camera.position.set(200, 200, 200);
camera.lookAt(0, 0, 0);

// 创建渲染器
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 渲染
function render() {
	requestAnimationFrame(render);
	renderer.render(scene, camera);
}
render();

//添加坐标轴辅助器
const axesHelper = new THREE.AxesHelper(200);
scene.add(axesHelper);

//轨道控制器
const controls = new OrbitControls(camera, renderer.domElement);
controls.addEventListener("change", function () {
	renderer.render(scene, camera);
});

//调试工具
const gui = new GUI();

const meshFolder = gui.addFolder('立方体');
meshFolder.addColor(mesh.material, 'color');
meshFolder.add(mesh.position, 'x').step(10);
meshFolder.add(mesh.position, 'y').step(10);
meshFolder.add(mesh.position, 'z').step(10);

const lightFolder = gui.addFolder('灯光');
lightFolder.add(pointLight.position, 'x').step(10);
lightFolder.add(pointLight.position, 'y').step(10);
lightFolder.add(pointLight.position, 'z').step(10);
lightFolder.add(pointLight, 'intensity').step(1000);

